requireJS(['constant', 'site', 'handlebars', 'public'], function (Constant, site, Handlebars, Public) {
    Constant.initHandlebars(Handlebars)
    var url = {
        a: "manager/queryPagePersonalPublicList.do",
        b_listLabel: "/manager/listLabel.do",
        c_setLabel: "manager/setLabel.do",
        d_queryTraceLogsList: "manager/queryTraceLogsListByPersonalId.do",//查询日志
        e_insertTraceLogs: "manager/insertTraceLogs.do",// 新增日志
        f_deleteTraceLogs: "manager/deleteTraceLogs.do",//删除日志
        g_editTraceLogs: "manager/editTraceLogs.do"
    }
    var adminId;
    var personId = '';
    var payee;
    var label_id;
    var homephone;

    var all_data = {
        pageNum: 1,
        locked: 1,
        roleId: JSON.parse(localStorage.getItem('content')).admin.roleid,
        //adminId: JSON.parse(localStorage.getItem('content')).admin.id
    }
    var selectOrderData = {
        pageNum: 1
    }
    var selectAdminData = {
        pageNum: 1
    }
    var udpateAdmin = {};
    var state;
    var selectProductALlData = {
        pageNum: 1
    };
    var editpid;

    function all_list() {
        site.send({
            url: url.a,
            //async:false
            data: all_data,
            callback: function (data) {
                var list = JSON.parse(data)
                if (list.type == '1') {
                    $("#personalTotal").text()
                    var source = $("#personalPublicList_tpl").html();
                    var template = Handlebars.compile(source);

                    var menuIndex = getAurlparam('h') || 0;
                    var thirdMenusIndex = getAurlparam('t') || 0;
                    var leftIndex = getAurlparam('i') || 0;

                    var storageContent = JSON.parse(localStorage.getItem('content'));

                    var obj = {
                        content: list,
                        fourthMenus: storageContent.menus[menuIndex].children[leftIndex].children[thirdMenusIndex].children || {}
                    }

                    var html = template(obj);
                    $('#personalPublicList').html(html);

                    var source = $("#special_fourth_tpl").html()
                    var template = Handlebars.compile(source)
                    var html = template(storageContent.menus[menuIndex].children[leftIndex].children[thirdMenusIndex].children)
                    $(".addPerson").remove();
                    $('.public-botPage-left').append(html)

                    if (list.content) {
                        $('.result').html(list.content.total ? list.content.total : '0');
                    }

                    $('.all-page-container').createPager({
                        current: all_data.pageNum,
                        total: list.content.total,
                        pageSize: list.content.pageSize,
                        needInput: false,
                        backFn: function (current) {
                            all_data.pageNum = current;
                            all_list();
                        }
                    })


                    Public.record('t_personal_public');
                }
                onBindFun();
            }

        })
    }

    all_list();
    var queryTraceLogsdata = {
        pageNum: "1",
        logs_type: "5",
        personal_id: ""
    }
    var tagSetId;
    var delect_ids = {
        ids: ""
    }
    var edit_traceLog = {
        id: "",
        content: ""
    }
    var block_list = {
        ids: "",
        locked: "",
        lockedContent: ""
    }
    // 传入参数
    var frontData = {
        personalId: '',
        pageNum: ''
    };

    function onBindFun() {

        $('.focus').on('click',function(){
            if($(this).hasClass('icon-aixin1')){
                $(this).removeClass('icon-aixin1').addClass('icon-aixin')
            }else{
                $(this).removeClass('icon-aixin').addClass('icon-aixin1')
            }
        })

        //拿到所有的复选框，当有复选框没选上的时候,取消全选
        $("input:checkbox[name='ch_id']").on('click', function () {
            var checkboxs = $("input:checkbox[name='ch_id']");
            var sum = 0;
            var length = checkboxs.length;
            $.each(checkboxs, function (i, checkbox) {
                if ($(checkbox).prop("checked")) {
                    sum++;
                }
            })
            if (sum == length) {
                $('#checkAllOrNot').prop("checked", true);
            } else {
                $('#checkAllOrNot').prop("checked", false);
            }
        })


// 全选和全不选
        $("#checkAllOrNot").on('click', function () {

            $("input[name='ch_id']").prop("checked", $(this).prop("checked"))

        })

// select菜单栏的change事件
        $(".custlistSelect").on('change', function () {
            adminId = $(this).data('adminid');
            personId = $(this).data('personalid');
            payee = $(this).data('payee');
            homephone = $(this).data('homephone');
            label_id = $(this).data('label_id');
            var obj = $(this).find("option:selected");
            // 编辑客户
            if (obj.val() == 'editPerson') {
                selectProductALlData = {};
                selectProductALlData.pid = personId;
                selectProductALlData.status = '2';
                selectProductALlFun();

                $(".tabHint").val('-1')
                editpid = personId;
            }
            // 拉黑名单
            if (obj.val() == 'lockPerson') {
                $(".blacklist").css("display", "block")
                $(".tabHint").val('-1')
                block_list.ids = personId;
                $(".block_list_name").text(payee)

            }
            // 更换业务员
            if (obj.val() == 'changeSalesMan') {
                selectAdminData.admin_id = JSON.parse(localStorage.getItem('content')).admin.id;
                udpateAdmin.pid = personId;
                changeAdminFun(adminId);
                $(".tabHint").val('-1')
            }
            //查看关联订单
            if (obj.val() == 'checkReOrder') {
                selectOrderData = {
                    personalId: $(this).data('personalid'),
                    pageNum: 1
                }
                //selectOrderData.personalId = $(this).data('personalid');
                selectContactOrder();
                $(".tabHint").val('-1')
            }
            //查看手机通讯录
            if (obj.val() == 'personalBook') {
                var personalId = personId
                var pageNum = $("#pageNum").val();
                // window.location.href="customerManager/phoneAddressBook/phone_address_book.html?personalId="+personalId+"&pageNum="+pageNum+""
                $(".tabHint").val('-1')
                $(".phone_Book_window").css("display", "block")
                frontData.personalId = personalId;
                frontData.pageNum = pageNum;
                phoneBookList();
            }

            if (obj.val() == 'setLabel') {
                $(".tagSet_window_select option:first").prop('selected', true);
                tagSetId = personId;
                var labelId = label_id ? label_id : '1';
                $(".tagSet_window").css("display", "block")
                $(".tagSet_window_select").val(labelId);
                $(".tabHint").val('-1')
            }
            if (obj.val() == 'personLocation') {
                var pId = personId;
                $(".getAddress_window").css("display", "block")
                $(".tabHint").val('-1')
                $(".map_window_name span").text(payee)
                $(".map_window_phone span").text(homephone)
                getAddressSelect(pId);
            }
            if (obj.val() == 'traceLogs') {
                var pid = personId;
                $(".search_traceLog_username").val("");
                $(".search_traceLog_content").val("");
                $(".trace_log_window").css("display", "block")
                $(".tabHint").val('-1')
                queryTraceLogsdata.personal_id = pid;
                queryTraceLogsList();
            }
        })


        // select菜单栏的change事件
        $(".all_block_list").on('change', function () {
            var obj = $(this).find("option:selected");
            // 编辑客户
            if (obj.val() == '1') {
                var val = $(this).find("option:selected").val();
                // 批量删除
                var inp = $("input[name='ch_id']");//获得所有check按钮
                var count = 0;//计数
                for (var i = 0; i < inp.length; i++) {
                    if (inp[i].checked) {
                        count++;
                        if (count < 2) {
                            block_list.ids = inp[i].value;
                        } else {
                            block_list.ids += ("," + inp[i].value);
                        }
                    }
                }
                if (count != 0) {
                    $(".blacklist").css("display", "block")
                    $(".block_list_name").text("所选")
                    block_list.lockedContent = $(".block_list_content").val();
                    block_list.locked = 2;
                } else {
                    Constant.fn.Message('I', "未选择");
                }
                $(".tabHint").val('-1')
                console.log(block_list)
            }


        })

        $(".operationRecord").on('click', function () {
            site.send({
                url: 'manager/selectPageLogList.do',
                //async:false
                data: {
                    pageNum: 1,
                    Table: 't_order_public',
                    tableId: $(this).data('id')
                },
                callback: function (data) {
                    var list = JSON.parse(data)
                    if (list.type == '1') {
                        var template = Handlebars.compile($("#recordList_content_tpl").html())
                        $("#recordList_content").html(template(list));
                        $(".RecordWinBox").show();
                    }
                }
            })
        })
    }

    // 录入订单
    $(".addCustomerBtn").on('click', function () {
        personId = ''
        selectProductALlData = {};
        selectProductALlData.pid = '';
        selectProductALlData.status = '1';
        selectProductALlFun();
    })
    // $(".headerIcon ").on('click', function () {
    //     $(".winBox").css("display", "none")
    //
    // })


    //test
// 标签设置
    // 显示所有标签列表
    site.send({
        url: url.b_listLabel,
        //async:false
        data: {},
        callback: function (data) {
            var list = JSON.parse(data)
            if (list.type == '1') {
                var source = $("#tag_set_content_tpl").html();
                var template = Handlebars.compile(source);
                var html = template(list.content);
                $('#tag_set_content').html(html);
            }
        }
    })
    $(".tagSet_commit").click(function () {
        var obj_select = $(".tagSet_window_select").find("option:checked");

        site.send({

            url: url.c_setLabel,
            //async:false
            data: {
                id: tagSetId,
                label: obj_select.val()
            },
            callback: function (data) {
                var list = JSON.parse(data)

                if (list.type == 1) {

                    $(".tagSet_window").hide();
                    Constant.fn.Message('T', list.msg)
                    pjaxReload();
                    //all_list();
                } else {
                    Constant.fn.Message('F', list.msg)
                }


            }

        })
    })
    var phoneBookList = function () {
        // 查询联系人信息
        site.send({

            url: "manager/queryPhoneBookListByPersonalId.do",
            //async:false
            data: frontData,
            callback: function (data) {
                var list = JSON.parse(data)
                console.log(data)
                if (list.type == '-1') {
                    Constant.fn.Message('F', list.msg)
                    var a = list.content.list;
                    if (a[0] == null) {
                        Constant.fn.Message('F', '查询为空')
                    }

                    var source = $("#PhoneBookList_tpl").html();
                    var template = Handlebars.compile(source);

                    var html = template(list);
                    $('#PhoneBookList').html(html);

                    // 分页


                    $('.customer-page-container').createPager({
                        current: frontData.pageNum,
                        total: list.content.total,
                        pageSize: list.content.pageSize,
                        needInput: false,
                        backFn: function (current) {
                            frontData.pageNum = current;
                            phoneBookList();
                        }
                    })
                } else {
                    Constant.fn.Message('F', list.msg)
                }


            }

        })

        //拿到所有的复选框，当有复选框没选上的时候,取消全选
        $("input:checkbox[name='ch_id2']").on('click', function () {
            var checkboxs = $("input:checkbox[name='ch_id2']");
            var sum = 0;
            var length = checkboxs.length;
            $.each(checkboxs, function (i, checkbox) {
                if ($(checkbox).prop("checked")) {
                    sum++;
                }
            })
            if (sum == length) {
                $('#checkAllOrNot2').prop("checked", true);
            } else {
                $('#checkAllOrNot2').prop("checked", false);
            }
        })


// 全选和全不选
        $("#checkAllOrNot2").on('click', function () {

            $("input[name='ch_id2']").prop("checked", $(this).prop("checked"))

        })

        // 单个删除
        var ids = {
            ids: 0

        }
        // $(".delect_phone").on('click',function () {
        //     ids.ids=$(this).data('id');
        //     delect_phone (ids);
        // })

        // 删除方法
        function delect_phone(ids) {
            site.send({
                url: "manager/deletePhone.do",
                //async:false
                data: ids,
                callback: function (data) {
                    var list = JSON.parse(data);
                    if (list.type == 1) {
                        pjaxReload();
                    } else {
                        Constant.fn.Message('F', list.msg);
                    }
                }
            })
        }

// 批量删除
        $(".batch_delete").on('change', function () {
            var obj = $(this).find("option:selected");
            if (obj.val() == 1) {
                var inp = $("input[name='ch_id2']");
                var count = 0;//计数
                for (var i = 0; i < inp.length; i++) {
                    if (inp[i].checked) {
                        count++;
                        if (count < 2) {
                            ids.ids = inp[i].value;
                        } else {
                            ids.ids += ("," + inp[i].value);
                        }
                    }
                }
                if (count != 0) {
                    delect_phone(ids)
                } else {
                    Constant.fn.Message('I', "未选择")
                }
                $(".batch_delete").val('-1')
            }
        })

    }


    // 搜索按钮
    $(".search_phoneNameOrPhone_Btn").on("click", function () {
        frontData.phoneName = $(".search_phoneName").val();
        frontData.phone = $(".search_phone").val();
        phoneBookList();
    })

    var xL, yL;

    //获得经纬度
    function getAddressSelect(id) {
        $("#container").css("display", "block");
        site.send({
            url: "manager/getLongitudeAndLatitude.do",
            //async:false
            data: {id: id},
            callback: function (data) {
                var list = JSON.parse(data);
                if (list.type == '1') {
                    $(".map_window").css("display", "block")
                    xL = list.content.longitude;
                    yL = list.content.latitude;
                    showMap(xL, yL);
                } else {
                    Constant.fn.Message('F', list.msg)
                }

            }

        })

    }

    // 显示地图
    function showMap(x, y) {
        var map = new AMap.Map("containerMap", {
                resizeEnable: true,
                zoom: 18
            }),
            lnglatXY = [x, y]; //已知点坐标
        //逆地理编码
        var geocoder = new AMap.Geocoder({
            radius: 1000,
            extensions: "all"
        });
        geocoder.getAddress(lnglatXY, function (status, result) {
            if (status === 'complete' && result.info === 'OK') {
                geocoder_CallBack(result);
            }
        });
        var marker = new AMap.Marker({  //加点
            map: map,
            position: lnglatXY
        });
        map.setFitView();

        function geocoder_CallBack(data) {
            var address = data.regeocode.formattedAddress; //返回地址描述
            document.getElementById("result").innerHTML = address;
        }
    }

    // 查询跟踪日志
    function queryTraceLogsList() {
        site.send({
            url: url.d_queryTraceLogsList,
            //async:false
            data: queryTraceLogsdata,
            callback: function (data) {
                var list = JSON.parse(data);
                var source = $("#trace_log_content_tpl").html();
                var template = Handlebars.compile(source);
                var html = template(list);
                $('#trace_log_content').html(html);

                if (list.type == '1') {

                }
                else {
                    Constant.fn.Message('F', list.msg)

                }
                // 分页
                $('.trace-page-container').createPager({
                    current: queryTraceLogsdata.pageNum,
                    total: list.content.total,
                    pageSize: list.content.pageSize,
                    needInput: false,
                    backFn: function (current) {
                        queryTraceLogsdata.pageNum = current;
                        queryTraceLogsList();
                    }
                })

                //删除日志
                $(".delect_trace_log").click(function () {
                    delect_ids.ids = $(this).data("id");
                    delect_trace_log();
                })
                // 编辑日志
                $(".edit_trace_log").click(function () {
                    edit_traceLog.id = $(this).data("id");
                    state = 'edit';
                    newAndEditTraceLogWindow(state, $(this).data("content"));
                })
                //拿到所有的复选框，当有复选框没选上的时候,取消全选
                $("input:checkbox[name='ch_id3']").on('click', function () {
                    var checkboxs = $("input:checkbox[name='ch_id3']");
                    var sum = 0;
                    var length = checkboxs.length;
                    $.each(checkboxs, function (i, checkbox) {
                        if ($(checkbox).prop("checked")) {
                            sum++;
                        }
                    })
                    if (sum == length) {
                        $('#checkAllOrNot3').prop("checked", true);
                    } else {
                        $('#checkAllOrNot3').prop("checked", false);
                    }
                })

                $("#checkAllOrNot3").on('click', function () {

                    $("input[name='ch_id3']").prop("checked", $(this).prop("checked"))

                })
                $(".all_trace_delete").on('change', function () {
                    var obj = $(this).find("option:selected");
                    if (obj.val() == 1) {
                        var inp = $("input[name='ch_id3']");
                        var count = 0;//计数
                        for (var i = 0; i < inp.length; i++) {
                            if (inp[i].checked) {
                                count++;
                                if (count < 2) {
                                    delect_ids.ids = inp[i].value;
                                } else {
                                    delect_ids.ids += ("," + inp[i].value);
                                }
                            }
                        }
                        if (count != 0) {
                            delect_trace_log()
                        } else {
                            Constant.fn.Message('I', "未选择")
                        }


                    }
                    $(".all_trace_delete").val('-1')
                })


            }
        })

    }

    //新增跟踪日志弹窗
    $(".trace_log_add").click(function () {
        state = 'new';
        newAndEditTraceLogWindow('new', 0);
    })

    //新增和编辑弹框
    function newAndEditTraceLogWindow(state, content) {

        $(".add_trace_log_window").css("display", "block");
        if (state == 'new') {
            $(".newAndEditLog_title").text("新增客户跟踪日志")
            $(".newAndEditLog_content").html("<span style='color: red;'>*</span>新增的日志内容：")
            $(".add_trace_log_text").val('')


        }
        if (state == 'edit') {
            $(".add_trace_log_text").val(content)
            $(".newAndEditLog_title").text("编辑客户跟踪日志")
            $(".newAndEditLog_content").html("<span style='color: red;'>*</span>编辑的日志内容:")


        }
    }

    $(".add_trace_log_window_commit").click(function () {
        if (state == 'new') {
            site.send({
                url: url.e_insertTraceLogs,
                //async:false
                data: {
                    personal_id: queryTraceLogsdata.personal_id,
                    logs_type: "5",
                    content: $(".add_trace_log_text").val()
                },
                callback: function (data) {
                    var list = JSON.parse(data);
                    if (list.type == 1) {
                        Constant.fn.Message('T', list.msg)
                        queryTraceLogsdata.content = '';
                        queryTraceLogsList();
                        $(".trace_log_window").css("display", "block")
                        $(".add_trace_log_window").css("display", "none");
                    } else {
                        Constant.fn.Message('F', list.msg)
                    }
                }

            })
        }
        if (state == 'edit') {
            edit_traceLog.content = $(".add_trace_log_text").val();
            site.send({
                url: url.g_editTraceLogs,
                //async:false
                data: edit_traceLog,
                callback: function (data) {
                    var list = JSON.parse(data);
                    if (list.type == 1) {
                        Constant.fn.Message('T', list.msg)
                        queryTraceLogsList();
                        $(".trace_log_window").css("display", "block")
                        $(".add_trace_log_window").css("display", "none");
                    } else {
                        Constant.fn.Message('F', list.msg)
                    }
                }
            })
        }
    })
    //
    $(".add_trace_log_window_cancel").click(function () {
        $(".trace_log_window").css("display", "block")
        $(".add_trace_log_window").css("display", "none");

    })
    //跟踪日志搜索
    $(".search_traceLog_Btn").click(function () {
        queryTraceLogsdata.add_username = $(".search_traceLog_username").val();
        queryTraceLogsdata.content = $(".search_traceLog_content").val();
        queryTraceLogsList();
    })

//
    function delect_trace_log() {
        site.send({
            url: url.f_deleteTraceLogs,
            //async:false
            data: delect_ids,
            callback: function (data) {
                var list = JSON.parse(data);
                if (list.type == 1) {
                    Constant.fn.Message('T', list.msg)
                    queryTraceLogsList();
                } else {
                    Constant.fn.Message('F', list.msg)
                }
            }
        })
    }

// 拉黑

    $(".black_list_commit").click(function () {
        block_list.lockedContent = $(".block_list_content").val();
        block_list.locked = 2;
        block_list_fun();
    })


//拉黑名单
    function block_list_fun() {
        site.send({
            url: "manager/updatePersonalLocked.do",
            //async:false
            data: block_list,
            callback: function (data) {
                var list = JSON.parse(data);

                if (list.type == 1) {
                    $('.blacklist').toggle();
                    Constant.fn.Message("T", list.msg);
                    pjaxReload()
                } else {
                    Constant.fn.Message('F', list.msg);
                }


            }
        })
    }

    // 省市区
    // ajaxqueryRegion.do
    var sshData = {
        pageNum: 1,
        parentId: 0
    }

    function ssq(a) {
        sshData.parentId = a;
        site.send({
                url: "manager/ajaxqueryRegion.do",
                // async:false,
                data: sshData,
                callback: function (data) {
                    var list = JSON.parse(data);
                    if (a == 0) {
                        var source = $("#sousuo_shi_tpl").html();
                        var template = Handlebars.compile(source);
                        var html = template(list);
                        $('#sousuo_shi').html(html);
                    }
                    if (a != 0) {
                        var source = $("#sousuo_shi_tpl2").html();
                        var template = Handlebars.compile(source);
                        var html = template(list);
                        $('#sousuo_shi2').html(html);
                    }
                    $(".selectjia_a").on('change', function () {
                        var obj = $(this).find("option:selected").val()
                        ssq(obj)
                    })
                }
            }
        )

    }


    ssq(0);
    // 部门
    /*site.send({
        url: "manager/selectDepartmentByLogin.do",
        //async:false
        data: {},
        callback: function (data) {
            var list = JSON.parse(data);
            var source = $("#sousuo_department_tpl").html();
            var template = Handlebars.compile(source);
            var html = template(list);
            $('#sousuo_department').html(html);
        }
    })*/

    var role = function () {
        var content = JSON.parse(localStorage.getItem('content'));
        console.log(content)
        // 角色
        site.send({
            url: "manager/selectAdminSalesman.do",
            //async:false
            data: {
                pageNum: 1,
                admin_id: content.admin.id
            },
            callback: function (data) {
                var list = JSON.parse(data);
                var source2 = $("#sousuo_role_tpl").html();
                var template2 = Handlebars.compile(source2);
                var html2 = template2(list.content);
                $('#sousuo_role').html(html2);

            }
        })


    }

    role();

    $(".selectjia_b").on('change', function () {
        var obj = $(this).find("option:selected").val();
        ssq(obj)

    })

    function ssq2(a) {
        sshData.parentId = a;
        site.send({
                url: "manager/ajaxqueryRegion.do",
                //async:false
                data: sshData,
                callback: function (data) {
                    var list = JSON.parse(data);
                    var source = $("#sousuo_shi_tpl3").html();
                    var template = Handlebars.compile(source);
                    var html = template(list);
                    $('#sousuo_shi3').html(html);
                }
            }
        )
    }

    $("#sousuo_shi2").on('change', function () {
        var obj = $(this).find("option:selected").val()
        ssq2(obj)
    })

    $("#select_sendM").on('change', function () {
        var obj = $(this).find("option:selected").val()

    })
    $(".serach_btn").click(function () {
        all_data = {};
        all_data.roleId = JSON.parse(localStorage.getItem('content')).admin.roleid;
        //all_data.adminId = JSON.parse(localStorage.getItem('content')).admin.id;

        if ($(".sousuo_keyword").val() != null && $(".sousuo_keyword").val() != '') {
            all_data.searchKey = $(".sousuo_keyword").val();
        }
        if ($("#select_sendM").val() !== null && $("#select_sendM").val() != '') {
            all_data.adminId = $("#select_sendM").val();
        }

        all_data.locked = 1;
        if ($(".selectjia_a").val() != null && $(".selectjia_a").val() != '') {
            all_data.addrProvince = $(".selectjia_a").val()
        }
        if ($("#sousuo_shi2").val() != null && $("#sousuo_shi2").val() != '') {
            all_data.addrCity = $("#sousuo_shi2").val()

        }
        if ($("#sousuo_shi3").val() != null && $("#sousuo_shi3").val() != '') {
            all_data.addrArea = $("#sousuo_shi3").val()

        }
        if ($(".sousuo_department_select").val() != null && $(".sousuo_department_select").val() != '') {
            all_data.departmentId = $(".sousuo_department_select").val()

        }


        all_list();
    })


    // 编辑客户
    function selectProductALlFun() {
        site.send({
            url: 'manager/selectProductALl.do',
            //async:false
            data: selectProductALlData,
            callback: function (data) {
                var list = JSON.parse(data)
                if (list.type == '1') {
                    $(".editProduct_window").show();

                    //初始化弹框内容
                    $("#editSelectType").val('');
                    $("#editSerachContent").val('');

                    $("#total").text(list.content.total)
                    var template = Handlebars.compile($("#productList_content_tpl").html())
                    $("#productList_content").html(template(list))

                    //list点击事件
                    $("#productList_content tr").click(function () {
                        if (selectProductALlData.pid != '') {
                            pjaxGo('customerManager/customerlist/customerEdit.html?pid=' + selectProductALlData.pid + '&productId=' + $(this).data('id') + '')
                        } else {
                            pjaxGo('customerManager/customerlist/customerEdit.html?productId=' + $(this).data('id') + '')
                        }
                    })

                } else {
                    Constant.fn.Message('F', list.msg);
                }
            }
        })
    }

    $("#search_edit_Btn").on('click', function () {
        selectProductALlData = {
            pageNum: 1,
            pid: personId,
        }
        selectProductALlData.status = personId ? 2 : 1;
        if ($('#editSelectType').val() != '') {
            selectProductALlData.type = $('#editSelectType').val();
        }
        if ($('#editSerachContent').val() != '' && $('#editSerachContent').val().trim()) {
            selectProductALlData.name = $('#editSerachContent').val();
        }
        selectProductALlFun();
    })

    // 查看关联订单
    function selectContactOrder() {
        site.send({
            url: "manager/selectOrderPageListByPid.do",
            // async: false,
            data: selectOrderData,
            callback: function (data) {
                var list = JSON.parse(data)
                if (list.type == '1') {
                    $(".associatedOrder").css("display", "block")
                    var list = JSON.parse(data)
                    var template = Handlebars.compile($("#dataList_content_tpl").html())
                    var html = template(list)
                    $("#dataList_content").html(html)
                } else {
                    Constant.fn.Message('F', list.msg);
                }


            }
        })

    }

    $("#selectOrderSerach").on('click', function () {
        if ($('.productName').val()) {
            selectOrderData.productName = $('.productName').val();
        }
        else {
            delete selectOrderData.productName
        }
        selectContactOrder();
    })

    // 更换业务员
    function changeAdminFun(admin_id) {

        site.send({
            url: "manager/selectAdminSalesman.do",
            // async: false,
            data: selectAdminData,
            callback: function (data) {
                var list = JSON.parse(data)
                if (list.type == '1') {
                    if (!list.content) {
                        $('.noPeople').show();
                    }
                    var obj = {
                        admin_id: admin_id,
                        list: list
                    }
                    $(".replacement").css("display", "block")
                    var list = JSON.parse(data)
                    var template = Handlebars.compile($("#admin_content_tpl").html())
                    var html = template(obj)
                    $("#admin_content").html(html)
                    $("#admin_content select option[value='" + adminId + "']").attr("selected", "selected");
                } else {
                    Constant.fn.Message('F', list.msg);
                }


            }, callError: function () {

            }
        })

        $("#changeCommitBtn").on('click', function () {
            if ($("#admin_content div select").val() != '') {
                udpateAdmin.admin_id = $("#admin_content div select").val();
            }
            site.send({
                url: "manager/udpateAdminSalesman.do",
                // async: false,
                data: udpateAdmin,
                callback: function (data) {
                    var list = JSON.parse(data)
                    if (list.type == '1') {
                        $(".replacement").css("display", "none")
                        Constant.fn.Message('T', list.msg);
                        pjaxReload();
                    } else {
                        Constant.fn.Message('F', list.msg);
                    }
                }
            })
        })
    }
})

